//
//  UIBarButtonItem+Extension.swift
//  WeiBo
//
//  Created by Apple on 2017/5/30.
//  Copyright © 2017年 KY. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //  扩展便利构造函数, 使用默认参数
    convenience init(title: String, imageName: String? = nil, target: Any, action: Selector) {
        self.init()
        let button = UIButton()
        //  添加点击事件
        button.addTarget(target, action: action, for: .touchUpInside)
        if let imgName = imageName {
            button.setImage(UIImage(named: imgName), for: .normal)
        }
        button.setTitle(title, for: .normal)
        //  设置文字颜色
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //  设置字体大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.sizeToFit()
        //  设置自定义视图
        customView = button
    }

}
